package com.aidex.web.controller.biz;

import java.util.List;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.BillInfo;
import com.aidex.biz.service.BillInfoService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 对账信息Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2023-09-27
 */
@RestController
@RequestMapping("/biz/bizBillInfo")
public class BillInfoController extends BaseController
{
    @Autowired
    private BillInfoService billInfoService;

    /**
     * 查询对账信息列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBillInfo:list')")
    @GetMapping("/list")
    public R<PageInfo> list(BillInfo billInfo, HttpServletRequest request, HttpServletResponse response)
    {
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            billInfo.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
         }
        billInfo.setPage(new PageDomain(request, response));
        return R.data(billInfoService.findPage(billInfo));
    }

    /**
     * 获取对账信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBillInfo:query')")
    @GetMapping(value = "/{id}")
    public R<BillInfo> detail(@PathVariable("id") String id)
    {
        return R.data(billInfoService.get(id));
    }

    /**
     * 新增对账信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBillInfo:add')")
    @Log(title = "对账信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  BillInfo billInfo)
    {
        return R.status(billInfoService.save(billInfo));
    }

    /**
     * 修改对账信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBillInfo:edit')")
    @Log(title = "对账信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated BillInfo billInfo)
    {
        return R.status(billInfoService.save(billInfo));
    }


    /**
     * 删除对账信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBillInfo:remove')")
    @Log(title = "对账信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(billInfoService.deleteBillInfoByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBillInfo:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(billInfoService.findMaxSort(new BillInfo()));
    }

    /**
     * 导出对账信息列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBillInfo:export')")
    @Log(title = "对账信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(BillInfo billInfo)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    billInfo.setCompanyId(null);
            }else{
                         billInfo.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<BillInfo> list = billInfoService.findList(billInfo);
        ExcelUtil<BillInfo> util = new ExcelUtil<BillInfo>(BillInfo.class);
        return util.exportExcel(list, "对账信息数据");
    }

}
